﻿<%@ Page Title="介绍" Language="C#" MasterPageFile="~/GLOBAL.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Documents.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MAIN" runat="server">
<table width="100%" border="0" cellspacing="5" cellpadding="0">
    <tr>
    <td valign="top">
      <p>这个类库中包含了大量 .NET 程序所需的基础类，特别是数据库操作类、异常捕获类，已在多个企业级项目中使用。</p>
      <p>使用uoLib将使您在项目开发更加快捷方便：</p>
      <p><img src="images/blossom_033.png" align="right" vspace="3" hspace="3" /><h4>1. 提供运行时错误的输出、日志记录功能。<span class="att">[强烈推荐]</span></h4></p>
      <p>发现问题是解决问题的一半。<strong>系统提供了专用于捕获运行时异常的类，可以将这些运行时异常深入地捕获并输出出来。</strong>输出格式可以是.txt文本文件、.htm网页文件形式的日志，也可以直接在B/S项目运行时的页面上直接显示出来。</p>
      <p>这里有一个异常捕获的日志列表，先感性认识下：<a href="http://www.ourome.com/Errors/list.aspx" target="_blank">http://www.ourome.com/Errors/list.aspx</a>。</p>
      <p>这个异常捕获类可以深度挖掘出异常链。环境对比：</p>
      <ul>
        <li>.NET自带的异常显示页面（就是黄色的那个错误页面）只能显示一个异常，经常也只是浅表异常，无法深层次地挖掘出异常产生的实质原因。特别是在多层结构、多项目结构的解决方案中，系统自带的异常显示页面往往仅输出一个类似“引发类型为‘System.Web.HttpUnhandledException’的异常。”这样的信息，让人摸不着头脑。另一方面，当项目发布之后，仍然可能存在诸多不易发现但确实存在的Bug，而这些Bug所引发的异常在客户端显示时，您并不会获得这些异常发生的状况信息，导致您很难发现这些Bug的存在。</li>
        <li>但<strong>若使用uoLib的异常捕获类，可以深入地将引发异常的所有InnerException捕获并输出出来，无论多么深的异常都将被递归地捕获。系统还提供一个专用的HttpHandlers来显示这些异常捕获的日志，使您能不间断地跟踪项目运行的情况。</strong>您只需要在web.Config里设置一个httpHandlers配置节就可以毫无遗漏地获得最原始的项目异常资料。<strong>这些资料包括异常发生的时间、请求路径、请求参数、客户端浏览器、客户端IP等详细信息。</strong>为项目的健壮性提高提供坚实的基础。</li>
      </ul>
      
<p><img src="images/blossom_011.png" align="right" vspace="3" hspace="3" /><h4>2. 将数据库实例化为对象，高性能地适配各种数据库。</h4>
</p><p>系统提供了<span class="classobj">Database</span>这个类，您可以使用它来建立自己的数据库实例。它提供了大量常用的方法来进行数据库操作：
您只需要传入一个<span class="classobj">DbCommand</span>甚至是一条SQL语句即可直接执行它，或者得到一个包含数据集的<span class="classobj">DataSet</span>。在此过程
中，您无需在意数据库连接是否已打开，也无需烦恼什么时候数据库连接需要关闭，系统已经为您做好了一切事情。</p>
<p>
系统也以单件模式提供了若干单体数据库实例，使您的数据库操作更高效。在您的项目中，只会一次性地链接数据库，一次性生成唯一的数据库实例，大大提升项目的开发速度和执行效率。
而这些数据库单体实例在使用起来有特别方便，如您需要连接Sql Server数据库，<strong>只需要在web.config里面配置好链接字符串就可以在项目的任何地方使用<span class="classobj">SqlClientSqlServer.Instance</span>了，没错，只有一行代码！</strong>
</p>
<p>系统也提供了数据库类的基本超类和接口，您也可以在此基础上继承、组合以添加您自己的功能。</p>
      <p>在提供多数据库支持的系统中更有完美的发挥。环境对比：</p>
      <ul>
        <li>一般工厂模式架构的项目中，除为各个数据库写各自的数据层之外，都会有一个接口层介于数据层和业务层之间，代码比较复杂不易管理。</li>
        <li>但若用uoLib的实例化数据库对象，您只需写您需要的数据层即可，多个数据层和业务层能够完美匹配，无需再写接口层代码您的项目也能够很方便地在各种数据库之间切换。</li>
      </ul>
      <p>目前支持的数据库有：</p>
      <ul>
        <li>SQL Server 2000/2005/2008.</li>
        <li>Access 97/2000/2007</li>
        <li>Excel 97/2000/2007</li>
        <li>SQLite</li>
        <li>DSN （系统数据源、用户数据源、文件数据源）</li>
        <li>Oracle （未能实际测试）</li>
      </ul>
      <h4>3. 提供一系列的常用静态方法。</h4>
      <p>这些方法可以在保证项目稳定运行的情况下加快您项目开发的速度，使您的工作更高效</p></td>
    <td valign="top" width="405"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="90%" style="padding-left:10px;"><span class="att">最新版本 Version: 2.2</span><br />运行环境：.NET 2.0/3.5
          <br />
          <a href="sdk/" target="_blank">在线帮助文档</a>&nbsp;|&nbsp;
          <a href="sdk/uolib.chm">CHM帮助文档</a>
          </td>
        <td width="10%"><a href="download.aspx" title="免费下载 uoLib"><img src="images/download_0.gif" border="0" alt="下载 uoLib"/></a></td>
        </tr>
      </table>
      <a href="images/uolib.jpg" target="_blank"><img class="Image" alt="uoLib.dll 类视图" src="images/uolib_small.jpg" align="right" border="0" /></a>
      </td>
  </tr>
</table>

<h3>异常捕获类使用示例<a name="ErrorReporter"></a></h3>
<p>此功能是uoLib提供的特色功能，也是最推荐使用的功能。使用起来非常方便，在项目中引用uoLib之后只需要配置Global.asax即可。</p>
<pre><ol class="dp-c"><li class="alt"><span><span class="keyword">protected</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;Application_Error(</span><span class="keyword">object</span><span>&nbsp;sender,&nbsp;EventArgs&nbsp;e) &nbsp;</span></span></li><li><span>{ &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">if</span><span>&nbsp;(HttpContext.Current.AllErrors.Length&nbsp;&gt;&nbsp;0) &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">foreach</span><span>&nbsp;(Exception&nbsp;ex&nbsp;</span><span class="keyword">in</span><span>&nbsp;HttpContext.Current.AllErrors) &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uoLib.Web.Debugger.ErrorReporter.RecordErrors(ex); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpContext.Current.ApplicationInstance.CompleteRequest(); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</span></li><li class="alt"><span>} &nbsp;</span></li></ol></pre>
<p>这样设置之后，项目中一旦产生了运行时异常将自动被以日志形式记录下来。默认的日志类型是.htm文件，记录在~/Errors/目录下（需要有写入权限），您也可以通过配置<span class="classobj">uoLib.Web.Debugger.Configuration</span>来设置日志类型、存储路径，甚至关闭此功能。</p>
<p>如果您希望能以Web页面的形式访问到系统记录的异常日志，只需要配置web.config中httpHandlers一节即可：</p>
<pre><ol class="dp-xml"><li class="alt"><span><span class="tag">&lt;?</span><span class="tag-name">xml</span><span>&nbsp;</span><span class="attribute">version</span><span>=</span><span class="attribute-value">&quot;1.0&quot;</span><span>&nbsp;</span><span class="attribute">encoding</span><span>=</span><span class="attribute-value">&quot;utf-8&quot;</span><span class="tag">?&gt;</span><span>&nbsp;</span></span></li><li><span class="tag">&lt;</span><span class="tag-name">configuration</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">system.web</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">httpHandlers</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">add</span><span>&nbsp;</span><span class="attribute">verb</span><span>=</span><span class="attribute-value">&quot;*&quot;</span><span>&nbsp;</span><span class="attribute">path</span><span>=</span><span class="attribute-value">&quot;Errors/List.aspx&quot;</span><span>&nbsp;</span><span class="attribute">type</span><span>=</span><span class="attribute-value">&quot;uoLib.Web.HttpHandlers.ServerErrorList,uoLib&quot;</span><span class="tag">/&gt;</span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;/</span><span class="tag-name">httpHandlers</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span><span class="tag">&lt;/</span><span class="tag-name">system.web</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li><span class="tag">&lt;/</span><span class="tag-name">configuration</span><span class="tag">&gt;</span><span>&nbsp;</span></li></ol></pre>
<p>其中“Errors/List.aspx”可以是您希望的任意路径，不必存在这个.aspx文件。</p>
  <h3>数据库单体使用示例<a name="Singleton"></a></h3>
<p>uoLib类库在使用上极其方便。它为三种常用数据库类型分别提供了一个数据库单体实例，它们是：</p>
<ul>
  <li>oledb连接的Access：<span class="classobj">OleDbAccess</span></li>
  <li>SqlClient连接的SQL Server：<span class="classobj">SqlClientSqlServer</span></li>
  <li>odbc连接的SQLite：<span class="classobj">OdbcSQLite</span></li>
</ul>
<p>您可以在程序中直接使用这三个单体实例来访问相应的数据库。下面是示例代码：</p><p><strong>web.Config</strong></p><pre><ol class="dp-xml"><li class="alt"><span><span class="tag">&lt;?</span><span class="tag-name">xml</span><span>&nbsp;</span><span class="attribute">version</span><span>=</span><span class="attribute-value">&quot;1.0&quot;</span><span class="tag">?&gt;</span><span>&nbsp;</span></span></li><li><span class="tag">&lt;</span><span class="tag-name">configuration</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">connectionStrings</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">remove</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">&quot;*&quot;</span><span class="tag">/&gt;</span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">add</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">&quot;uoLib.SqlClientSqlServer&quot;</span><span>&nbsp;</span><span class="attribute">connectionString</span><span>=</span><span class="attribute-value">&quot;Data&nbsp;Source=127.0.0.1;Initial&nbsp;Catalog=NorthWind;User&nbsp;Id=sa;Password=;&quot;</span><span class="tag">/&gt;</span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">add</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">&quot;uoLib.OleDbAccess&quot;</span><span>&nbsp;</span><span class="attribute">connectionString</span><span>=</span><span class="attribute-value">&quot;&quot;</span><span class="tag">/&gt;</span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;</span><span class="tag-name">add</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">&quot;uoLib.OdbcSQLite&quot;</span><span>&nbsp;</span><span class="attribute">connectionString</span><span>=</span><span class="attribute-value">&quot;DRIVER=SQLite3&nbsp;ODBC&nbsp;Driver;Database=files/demo.db3;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;&quot;</span><span class="tag">/&gt;</span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="tag">&lt;/</span><span class="tag-name">connectionStrings</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li class="alt"><span class="tag">&lt;/</span><span class="tag-name">configuration</span><span class="tag">&gt;</span><span>&nbsp;</span></li><li></li></ol></pre>
<p>web.config文件中可以将数据库的连接字符串留空。如上面的配置中，可以不配置<span class="classobj">uoLib.OleDbAccess</span>的连接字符串，因为在 cs 代码中将另行写入。详见下：</p>
<pre><ol class="dp-c"><li class="alt"><span><span class="keyword">using</span><span>&nbsp;System; &nbsp;</span></span></li><li><span class="keyword">using</span><span>&nbsp;System.Data; &nbsp;</span></li><li class="alt"><span class="keyword">using</span><span>&nbsp;System.Data.Common; &nbsp;</span></li><li><span class="keyword">using</span><span>&nbsp;uoLib.Data.Singleton; &nbsp;</span></li><li class="alt"><span>&nbsp;</span></li><li><span class="keyword">namespace</span><span>&nbsp;DemoWeb &nbsp;</span></li><li class="alt"><span>{ &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;partial&nbsp;</span><span class="keyword">class</span><span>&nbsp;Demo&nbsp;:&nbsp;System.Web.UI.Page &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">protected</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;Page_Load(</span><span class="keyword">object</span><span>&nbsp;sender,&nbsp;EventArgs&nbsp;e) &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;</span></li><li><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;使用&nbsp;SqlClient&nbsp;链接字符串的&nbsp;Sql&nbsp;Server&nbsp;数据库 </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;2000/2005/2008均可。 </span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;链接字符串配置名称：uoLib.SqlClientSqlServer </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlClientSqlServer&nbsp;SQL&nbsp;=&nbsp;SqlClientSqlServer.Instance; &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">const</span><span>&nbsp;</span><span class="keyword">string</span><span>&nbsp;TABLENAME&nbsp;=&nbsp;</span><span class="string">&quot;Products&quot;</span><span>; &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DbCommand&nbsp;cmd&nbsp;=&nbsp;SQL.CreateCommand(</span><span class="string">&quot;SELECT&nbsp;TOP&nbsp;1&nbsp;ID&nbsp;FROM&nbsp;{0}&quot;</span><span>,&nbsp;TABLENAME); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataSet&nbsp;ds&nbsp;=&nbsp;SQL.SelectData(cmd); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">if</span><span>&nbsp;(ds&nbsp;==&nbsp;</span><span class="keyword">null</span><span>) &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(</span><span class="string">&quot;数据库为空！&quot;</span><span>); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">else</span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(</span><span class="keyword">string</span><span>.Format(</span><span class="string">&quot;共&nbsp;{0}&nbsp;行记录。&quot;</span><span>,&nbsp;ds.Tables[0].Rows.Count)); &nbsp;</span></li><li><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;使用&nbsp;OleDb&nbsp;链接字符串的&nbsp;Access&nbsp;数据库 </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;97/2000/2007均可。 </span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;链接字符串配置名称：uoLib.OleDbAccess </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OleDbAccess&nbsp;Access&nbsp;=&nbsp;OleDbAccess.Instance; &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Access.CreateConnection( &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OleDbAccess.CreateExampleConnectionString( &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Server.MapPath(</span><span class="string">&quot;files/test.mdb&quot;</span><span>),&nbsp;</span><span class="string">&quot;uonun&quot;</span><span>,&nbsp;</span><span class="string">&quot;ourome.com&quot;</span><span>) &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(Access.Conn.ConnectionString); &nbsp;</span></li><li><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;使用&nbsp;Odbc&nbsp;链接字符串的&nbsp;SQLite&nbsp;数据库。 </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//&nbsp;链接字符串配置名称：uoLib.OdbcSQLite </span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OdbcSQLite&nbsp;SQLite&nbsp;=&nbsp;OdbcSQLite.Instance; &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQLite.Conn.Open(); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//do&nbsp;something.. </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQLite.Conn.Close(); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</span></li><li class="alt"><span>} &nbsp;</span></li></ol></pre><p>注意：<ol>
  <li>要使用数据库的单体实例，必须在web.config里面配置相应名称的连接字符串节。（可以留空，但必须有这一节，如上例中的<span class="classobj">uoLib.OleDbAccess</span>）</li><li>由于使用了单体模式，因此在整个项目中，将只存在一个数据库实例，在简化了数据库使用的同时也提高了性能。不过如此一来，在整个系统中也将仅有一个相同数据库的实例。以<span class="classobj">SqlClientSqlServer</span>&nbsp;为例，您无法使用<span class="classobj">SqlClientSqlServer.Instance</span>来生成两个不同的数据库。（要在同一系统中使用多个相同数据库实例，请看Database的使用方法。）</li></ol></p>
<p><h3>Database类使用示例<a name="Database"></a></h3></p>
<p>如果uolib.dll提供的数据库单体实例无法满足您的需求，您可以使用<span class="classobj">Database</span>这个类来建立自己的数据库实例，它提供了比单体实例更多、更完善的方法和属性。下面对<span class="classobj">Database</span>类的使用作一个简单的示例：</p><pre><ol class="dp-c"><li class="alt"><span><span class="keyword">using</span><span>&nbsp;System; &nbsp;</span></span></li><li><span class="keyword">using</span><span>&nbsp;System.Data; &nbsp;</span></li><li class="alt"><span class="keyword">using</span><span>&nbsp;System.Data.Common; &nbsp;</span></li><li><span class="keyword">using</span><span>&nbsp;uoLib.Data; &nbsp;</span></li><li class="alt"><span>&nbsp;</span></li><li><span class="keyword">namespace</span><span>&nbsp;DemoWeb &nbsp;</span></li><li class="alt"><span>{ &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">public</span><span>&nbsp;partial&nbsp;</span><span class="keyword">class</span><span>&nbsp;Demo2&nbsp;:&nbsp;System.Web.UI.Page &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">protected</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;Page_Load(</span><span class="keyword">object</span><span>&nbsp;sender,&nbsp;EventArgs&nbsp;e) &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//声明数据库实例 </span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Database&nbsp;db&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;Database(ConnectionType.SqlClient); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//初始化数据库连接 </span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;db.CreateConnection( &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Database.CreateExampleConnectionString( &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string">&quot;127.0.0.1&quot;</span><span>,&nbsp;</span><span class="string">&quot;NorthWind&quot;</span><span>,&nbsp;</span><span class="string">&quot;sa&quot;</span><span>,&nbsp;</span><span class="string">&quot;&quot;</span><span>, &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ConnectionType.SqlClient) &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(db.Conn.ConnectionString); &nbsp;</span></li><li class="alt"><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//示例：执行&nbsp;DbCommand&nbsp; </span><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//可执行包括SELECT/INSERT/UPDATE/DELETE、存储过程等任何DbCommand命令 </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">int</span><span>&nbsp;_id&nbsp;=&nbsp;10; &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DbCommand&nbsp;cmd&nbsp;=&nbsp;db.CreateCommand(</span><span class="string">&quot;DELETE&nbsp;FROM&nbsp;[TABLE]&nbsp;WHERE&nbsp;ID=@id&quot;</span><span>); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.Parameters.Add(db.CreateParameter(</span><span class="string">&quot;@id&quot;</span><span>,&nbsp;System.Data.DbType.Int32,_id)); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Database.Execute(cmd); &nbsp;</span></li><li><span>&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//示例：使用存储过程、查询数据库 </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd&nbsp;=&nbsp;db.CreateCommand(</span><span class="string">&quot;myProcedure&quot;</span><span>); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.CommandType&nbsp;=&nbsp;CommandType.StoredProcedure; &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.Parameters.Add(db.CreateParameter(</span><span class="string">&quot;@id&quot;</span><span>,&nbsp;System.Data.DbType.Int32,&nbsp;_id)); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataSet&nbsp;ds&nbsp;=&nbsp;db.SelectData(cmd); &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">if</span><span>&nbsp;(ds&nbsp;==&nbsp;</span><span class="keyword">null</span><span>) &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(</span><span class="string">&quot;数据库为空！&quot;</span><span>); &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">else</span><span>&nbsp;{&nbsp; &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//do&nbsp;something... </span><span>&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</span></li><li class="alt"><span>} &nbsp;</span></li></ol></pre>
<p><span class="classobj">Database</span>类提供了很多的方法，此处无法写出所有的示例，您可以在使用中自行查看。uoLib中也提供了<span class="classobj">Database</span>的父类<span class="classobj">BaseProvider</span>以供继承。</p>

</asp:Content>
